/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import model.AmountOfIngredient;
import model.Recipe;

/**
 *
 * @author Jonas
 */
public class RecipePanel extends javax.swing.JPanel {

    private Recipe rp;
    private ImageIcon ic;
    private BufferedImage img;

    /**
     * Creates new form RecipePanel
     */
    public RecipePanel(Recipe rp) {
        this.rp = rp;
        initComponents();
        setSize(582, 100);
        setRpPanel();
    }

    public void setRpPanel() {
        String ingredients = "";
        jLabelName.setText(rp.getName());
        for (AmountOfIngredient aoi : rp.getIngredients()) {
            ingredients = ingredients + aoi.getIng().getName() + ", ";
        }
        jTextAreaIngredients.setText(ingredients);

        if (rp.getImage().trim().isEmpty()) {
            ic = new ImageIcon("src/res/default.png");
        } else {
            ic = new ImageIcon(rp.getImage());
        }
        jLabelImage.setIcon(ic);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelImage = new javax.swing.JLabel();
        jLabelName = new javax.swing.JLabel();
        jTextAreaIngredients = new javax.swing.JTextArea();

        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        setPreferredSize(new java.awt.Dimension(600, 100));

        jLabelName.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabelName.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelName.setText("Rettens navn");

        jTextAreaIngredients.setEditable(false);
        jTextAreaIngredients.setColumns(20);
        jTextAreaIngredients.setLineWrap(true);
        jTextAreaIngredients.setRows(5);
        jTextAreaIngredients.setWrapStyleWord(true);
        jTextAreaIngredients.setAutoscrolls(false);
        jTextAreaIngredients.setFocusable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabelImage, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextAreaIngredients)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                .addGap(3, 3, 3)
                .addComponent(jLabelName)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextAreaIngredients, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
            .addComponent(jLabelImage, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabelImage;
    private javax.swing.JLabel jLabelName;
    private javax.swing.JTextArea jTextAreaIngredients;
    // End of variables declaration//GEN-END:variables
}
